package com.ktgj.common.core.utils.xml;

import java.util.ArrayList;

public class XAttributeCollection extends ArrayList<XAttribute>
{
	private static final long serialVersionUID = 1786111994086780055L;

	public XAttribute get(String name)
	{
		return this.stream().filter(x -> x.getName().equals(name)).findFirst().orElse(null);
	}

	public void set(String name, String value)
	{
		XAttribute attribute = this.get(name);
		if (attribute == null)
		{
			this.add(new XAttribute(name, value));
		}
		else
		{
			attribute.setValue(value);
		}
	}

	public boolean containsAttribute(String name)
	{
		return this.stream().anyMatch(x -> x.getName().equals(name));
	}
}
